package com.example.demo2.controller;

import com.example.demo2.generator.entity.User;
import com.example.demo2.generator.entity.R;
import com.example.demo2.generator.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * (Login)表控制层
 *
 * @author makejava
 * @since 2024-09-07 13:55:43
 */
@Api(value = "用户Controller",tags = "用户测试接口")
@RestController
@RequestMapping("/login")
public class UserController {
    /**
     * 服务对象
     */
    @Autowired
    private UserService userService;


    @ApiOperation(value = "登录测试")
    @RequestMapping("/getLogin")
    @ResponseBody
    public R getLogin(@ApiParam(value = "用户名")@RequestParam("username") String username,@ApiParam(value = "密码") @RequestParam("password") String password){
        User login = userService.queryByPwdAnd(username, password);
        System.out.println("账号："+username);
        System.out.println("密码:"+password);
        System.out.println(login);
        if (login==null){
            System.out.println("登录失败");
            return  R.fail();
        }
        else
        {
            System.out.println("登录成功");
            return R.ok("登录成功",login);

        }
    }
    @ApiOperation(value = "查询所有用户")
    @RequestMapping("/getAllLogin")
    @ResponseBody
    public R getAllLogin() {
        System.out.println("执行查询所有用户");
        List<User> logins = userService.queryAllLogin();
        int loginByCount = userService.getLoginByCount();
        return R.ok(logins);

    }

}

